package com.hmdp.config;

import com.hmdp.inteceptor.LoginInteceptor;
import com.hmdp.inteceptor.TokenRefreshInterceptor;
import com.hmdp.utils.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.security.auth.Refreshable;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInteceptor loginInteceptor;
    @Autowired
    private TokenRefreshInterceptor tokenRefreshInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInteceptor).excludePathPatterns(
                "/user/login",
                "/user/code",
                "/voucher",
                "/voucher-order",
                "/blog",
                "/blog/hot"
        ).order(1);
        registry.addInterceptor(tokenRefreshInterceptor).addPathPatterns("/**").order(0);
    }
}
